// 模拟数据
import listData from "./list.js";
import courseList from "./courseList.js"

export function getData(pageNum, pageSize, type) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联
		
		setTimeout(()=>{
			try {
			let list = []
			let dat = []
			
			
			for(let i in listData){
				if(listData[i].type==0){
					dat.push(listData[i]);
				}
			}
			
			
			
			
			
			for (let i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
				if (i ===dat.length)break;
					
				list.push(dat[i])
				
			}
			
			list.sort(function(){
				return Math.random()-0.5;
			})
			
		    
			
			resolute(list);
			
		} catch (e) {
			//模拟接口请求失败
			reject(e);
		}

		},1000)
		
		
	})
}

export function getCourse(pageNum, pageSize, type) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联
		
		setTimeout(()=>{
			try {
			let list = []
			let dat = []
			for(let i in courseList){
				if(courseList[i].type==0){
					dat.push(courseList[i]);
				}
			}	
			for (let i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
				if (i ===dat.length)break;
					
				list.push(dat[i])
				
			}
			list.sort(function(){
				return Math.random()-0.5;
			})	
			resolute(list);
			
		} catch (e) {
			//模拟接口请求失败
			reject(e);
		}

		},1000)
		
		
	})
}

export function getCourselist(pageNum, pageSize, type) {
	return new Promise((resolute, reject) => {
		//延时一秒,模拟联
		
		setTimeout(()=>{
			try {
			let list = []
			let dat = []
			for(let i in courseList){
				if(courseList[i].type==type){
					dat.push(courseList[i]);
				}
			}	
			for (let i = (pageNum - 1) * pageSize; i < pageNum * pageSize; i++) {
				if (i ===dat.length)break;
				list.push(dat[i]);
			}
			list.sort(function(){
				return Math.random()-0.5;
			})	
			resolute(list);
			
		} catch (e) {
			//模拟接口请求失败
			reject(e);
		}

		},1000)
		
		
	})
}